<?php
class Model_Admin_Requests extends Model_Abstract{

    public function __construct() {
        parent::__construct();
    }

    public function getRequests(){
        return $this->db->query('SELECT * FROM `clean_requests` ORDER BY `id` DESC')->fetchAll();
    }

    public function getRequestsWithLimit($page, $limit, $order = 'id', $orderDir = 'DESC'){
        $startFrom=$page*$limit;

        $items = $this->db->query('SELECT * FROM `clean_requests` ORDER BY `' . $order . '` ' . $orderDir.' LIMIT ' . $startFrom . ',' . $limit)->fetchAll();
        return $items;
    }

    public function getRequestById($id){
        return $this->db->query('SELECT * FROM `clean_requests` WHERE `id` = ?',$id)->fetch();
    }

    public function deleteRequest($id){
        $result = $this->db->query('DELETE FROM `clean_requests` WHERE `id`=?', $id);

    }
    
    public static  function parseRequestCleanType($value){
        foreach (self::$CLEAN_TYPES as $key=>$val){
            if($key === $value){
                return $val;
            }
        }
    }
    
    public static function parseRequestHowOften($value){
        foreach (self::$PERIDIOCITY as $key=>$val){
            if($key === $value){
                return $val;
            }
        }
    }

    public static function parseRequestBathrooms($value){
        foreach (self::$BATHROOMS as $key=>$val){
            if($key === $value){
                return $val;
            }
        }
    }

    public static function parseRequestBedrooms($value){
        foreach (self::$BEDROOMS as $key=>$val){
            if($key === $value){
                return $val;
            }
        }
    }

    public static function parseRequestLevels($value){
        foreach (self::$LEVELS as $key=>$val){
            if($key === $value){
                return $val;
            }
        }
    }


}
